import { gsap } from 'gsap';

interface CustomPlugin {
  name: string;
  init: (target: any, value: any) => any;
}

export default defineNuxtPlugin((nuxtApp) => {
  // 确保插件在客户端运行
  if (process.client) {
    // 定义一些便利的随机函数
    gsap.registerPlugin({
      name: "random",
      init(target: any, value: any): any {
        if (typeof value === 'string' && value.startsWith('random(') && value.endsWith(')')) {
          const params = value.substring(7, value.length - 1).split(',');
          const min = parseFloat(params[0]);
          const max = parseFloat(params[1]);
          return Math.random() * (max - min) + min;
        }
        return value;
      }
    } as CustomPlugin);
  }

  return {
    provide: {
      gsap
    }
  };
}); 